home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / moden / tcom / tcomini.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-08  |  31.0 KB  |  1,020 lines

  1. {$G+,X+,F+}
  2.  
  3. {Conditional defines that may affect this unit}
  4. {$I AWDEFINE.INC}
  5.  
  6. {*********************************************************}
  7. {*                   TCOMINI.PAS 1.01                    *}
  8. {*        Copyright (c) TurboPower Software 1995         *}
  9. {*                 All rights reserved.                  *}
  10. {*********************************************************}
  11.  
  12. unit TcomIni;
  13.   {-INI file and configuration data for TCOM}
  14.  
  15. interface
  16.  
  17. uses
  18.   WinTypes,
  19.   WinProcs,
  20.   SysUtils,
  21.   Graphics,
  22.   OoMisc,
  23.   AdMisc,
  24.   AdModDB,
  25.   AdPort,
  26.   AdTerm,
  27.   AdDial,
  28.   AdProtcl;
  29.  
  30. {.INI file parameters}
  31. const
  32.   IniName         = 'TCOM.INI';
  33.  
  34.   tsTerminal      = 'DelphiTerminal';
  35.   tsPort          = 'Port';
  36.   tsFlow          = 'Flow control';
  37.   tsDev           = 'Device layer';
  38.   tsDirs          = 'Directories';
  39.   tsModem         = 'Modem';
  40.   tsDialer        = 'Dialer';
  41.   tsProtocols     = 'Protocols';
  42.   tsZmodem        = 'Zmodem';
  43.   tsBplus         = 'B+';
  44.   tsKermit        = 'Kermit';
  45.   tsAscii         = 'ASCII';
  46.  
  47.   tkFontColor     = 'Color';               tdFontColor     = $00C0C0C0; {!!.01}
  48.   tkFontHeight    = 'Height';              tdFontHeight    = -12;
  49.   tkFontName      = 'Name';                tdFontName      = 'Terminal';
  50.   tkFontStyle     = 'Style';               tdFontStyle     = [];
  51.   (*tkEmulation     = 'Emulation';           tdEmulation     = etAnsi;    {!!.01}*)
  52.  
  53.   tkComPort       = 'ComPort';             tdComPort       = 'COM1';
  54.   tkBaudRate      = 'BaudRate';            tdBaudRate      = 1200;
  55.   tkParity        = 'Parity';              tdParity        = pNone;
  56.   tkDataBits      = 'DataBits';            tdDataBits      = 8;
  57.   tkStopBits      = 'StopBits';            tdStopBits      = 1;
  58.  
  59.   tkHWFlow        = 'HWFlowCtl';           tdHWFlow        = 'CTS/RTS';
  60.  
  61.   tkSWFlowRecCtl  = 'ReceiveSwFlowCtl';    tdSWFlowRecCtl  = False;
  62.   tkSWFlowXmitCtl = 'TransmitSwFlowCtl';   tdSWFlowXmitCtl = False;
  63.   tkXonChar       = 'XonChar';             tdXonChar       = 17;
  64.   tkXoffChar      = 'XoffChar';            tdXoffChar      = 19;
  65.  
  66.   tkDevice        = 'Device';              tdDevice        = dlComm;
  67.   tkBufSize       = 'BufSize';             tdBufSize       = 16384;
  68.  
  69.   tkUploadDir     = 'UploadDir';
  70.   tkDownloadDir   = 'DownloadDir';
  71.  
  72.   tkRetries       = 'Retries';             tdRetries       = 10;
  73.   tkRetryWait     = 'RetryWait';           tdRetryWait     = 60;
  74.   tkAbortOnVoice  = 'AbortOnVoice';        tdAbortOnVoice  = False;
  75.   tkAbortOnBusy   = 'AbortOnBusy';         tdAbortOnBusy   = False;
  76.   tkAbortOnNC     = 'AbortOnNoCarrier';    tdAbortOnNC     = False;
  77.   tkAbortOnND     = 'AbortOnNoDialTone';   tdAbortOnND     = True;
  78.   tkAbortOnError  = 'AbortOnError';        tdAbortOnError  = True;
  79.  
  80.   tkOverwriteMode = 'OverwriteFiles';      tdOverwriteMode = wfWriteFail;
  81.   tkSavePartials  = 'SavePartials';        tdSavePartials  = False;
  82.   tkRTSWrite      = 'RTSWhenWriting';      tdRTSWrite      = True;
  83.  
  84.   tkZmodemAutoSt  = 'AutoStart';           tdZmodemAutoSt  = True;
  85.  
  86.   tkBplusEnabled  = 'Enabled';             tdBplusEnabled  = True;
  87.  
  88.   tkKermitErrChk  = 'ErrorCorrection';     tdKermitErrChk  = '1';
  89.   tkHiBitPrefix   = 'HiBitPrefix';         tdHiBitPrefix   = 89;
  90.   tkRepeatPrefix  = 'RepeatPrefix';        tdRepeatPrefix  = 126;
  91.   tkControlPrefix = 'ControlPrefix';       tdControlPrefix = 35;
  92.   tkPaddingCount  = 'PaddingCount';        tdPaddingCount  = 0;
  93.   tkPaddingChar   = 'PaddingChar';         tdPaddingChar   = 0;
  94.   tkMaxPackLength = 'MaxPacketLength';     tdMaxPackLength = 80;
  95.   tkTerminator    = 'Terminator';          tdTerminator    = 13;
  96.  
  97.   tkUploadCR      = 'UploadCR';            tdUploadCR      = aetNone;
  98.   tkUploadLF      = 'UploadLF';            tdUploadLF      = aetNone;
  99.   tkStopCtrlZ     = 'StopOnCtrlZ';         tdStopCtrlZ     = True;
  100.   tkEolCharacter  = 'EolChar';             tdEolCharacter  = 13;
  101.   tkDelayChar     = 'DelayAfterChar';      tdDelayChar     = 0;
  102.   tkDelayLine     = 'DelayAfterLine';      tdDelayLine     = 0;
  103.   tkDownloadCR    = 'DownloadCR';          tdDownloadCR    = aetNone;
  104.   tkDownloadLF    = 'DownloadLF';          tdDownloadLF    = aetNone;
  105.   tkTimeout       = 'DownloadTimeout';     tdTimeout       = 2000;
  106.  
  107.   {enumerated strings for INI file}
  108.   ePitches        = 'DEFAULT|VARIABLE|FIXED';
  109.   eEmulations     = 'NONE|ANSI|VT52|VT100';
  110.   eParities       = 'NONE|ODD|EVEN|MARK|SPACE';
  111.   eDevices        = 'NONE|COMMDRV|FOSSIL';
  112.   eOverwriteModes = 'NONE|FAIL|RENAME|OVERWRITE|RESUME';
  113.   eKermitCheck    = 'CSUM|CSUM2|CRC';
  114.   eUplCRXlat      = 'SEND|STRIP|BOOGA|SENDLF';
  115.   eUplLFXlat      = 'SEND|STRIP|SENDCR';
  116.   eDwnCRXlat      = 'KEEP|STRIP|BOOGA|ADDLF';
  117.   eDwnLFXlat      = 'KEEP|STRIP|ADDCR';
  118.  
  119.   {Misc}
  120.   BatchProtocols : Set of TProtocolType = [ptYModem, ptYmodemG, ptZmodem, ptKermit];
  121.  
  122. var
  123.   {terminal}
  124.   FontData     : TFont;
  125.   (*Emulation    : TEmulatorType; {!!.01}*)
  126.  
  127.   {Com parameters}
  128.   Com          : String[4];
  129.   Baud         : LongInt;
  130.   Parity       : TParity;
  131.   Databits     : Byte;
  132.   Stopbits     : Byte;
  133.  
  134.   {Flow parameters}
  135.   HdwFlow      : THWFlowOptionSet;
  136.   SfwFlow      : TSWFlowOptions;
  137.   XonChar      : Char;
  138.   XoffChar     : Char;
  139.  
  140.   {Buffer sizes}
  141.   InBuff       : Word;
  142.   OutBuff      : Word;
  143.   BufferFull   : Word;
  144.   BufferResume : Word;
  145.  
  146.   {Device}
  147.   Device       : TDeviceLayer;
  148.  
  149.   {Dirs}
  150.   UploadDir    : String[66];
  151.   DownloadDir  : String[66];
  152.  
  153.   {Modem}
  154.   ModemInfo    : TModemInfo;
  155.   DBFile       : TFileName;
  156.  
  157.   {Phonebook}
  158.   PhoneFile    : TFileName;
  159.  
  160.   {Capture}
  161.   CaptureFile  : TFileName;
  162.  
  163.   {$IFDEF Tracing}
  164.   TraceFile    : TFileName;
  165.   {$ENDIF}
  166.   {$IFDEF DispatchLogging}
  167.   DispLogFile  : TFileName;
  168.   {$ENDIF}
  169.  
  170.   {Dialer}
  171.   MaxDialTries : Integer;
  172.   RetryTime    : Integer;
  173.   DialerOpts   : TDialerOptions;
  174.  
  175.   {Protocol options}
  176.   WriteOpt     : TWriteFailAction;
  177.   SavePartials : Boolean;
  178.   RTSWrite     : Boolean;
  179.   LogFile      : TFileName;
  180.  
  181.   {Zmodem options}
  182.   ZmodemAutoSt : Boolean;
  183.  
  184.   {B+ options}
  185.   BplusEnabled : Boolean;
  186.  
  187.   {Kermit options}
  188.   ErrCheck     : Char;
  189.   HiBitPrefix  : Char;
  190.   RepeatPrefix : Char;
  191.   CtlPrefix    : Char;
  192.   PadCount     : Byte;
  193.   PadChar      : Char;
  194.   MaxPacketLen : Byte;
  195.   Terminator   : Char;
  196.  
  197.   {ASCII options}
  198.   UploadCR     : TAsciiEOLTranslation;
  199.   UploadLF     : TAsciiEOLTranslation;
  200.   StopCtrlZ    : Boolean;
  201.   EolChar      : Char;
  202.   DelayChar    : Word;
  203.   DelayLine    : Word;
  204.   DownloadCR   : TAsciiEOLTranslation;
  205.   DownloadLF   : TAsciiEOLTranslation;
  206.   AscTimeout   : Word;
  207.  
  208. const
  209.   IniBoolStr : array[False..True] of String[10] = ('FALSE', 'TRUE');
  210.   EnumDelim  = '|';
  211.  
  212. type
  213.   ENoIniSection = class(Exception) end;
  214.  
  215.   {INI file manager}
  216.   TIniFile = class(TObject)
  217.   private
  218.     FFileName   : array[0..79] of Char;
  219.     FSection    : array[0..255] of Char;
  220.     TempVar     : array[0..255] of Char;
  221.     TempData    : array[0..255] of Char;
  222.     TempDefault : array[0..255] of Char;
  223.  
  224.     function ReadSection : String;
  225.     procedure SetSection(const Sect : String);
  226.     function ReadFileName : TFileName;
  227.     procedure SetFileName(const FName : TFileName);
  228.  
  229.   public
  230.     property FileName : TFileName
  231.       read ReadFileName write SetFileName;
  232.     property Section : String
  233.       read ReadSection write SetSection;
  234.  
  235.     constructor Create; virtual;
  236.     destructor Destroy; virtual;
  237.  
  238.     {writing}
  239.     procedure WriteString(const Variable, Data : String);
  240.       {-Write a string to the INI file}
  241.     procedure WriteUCString(const Variable, Data : String);
  242.       {-Write an uppercase string to the INI file}
  243.     procedure WriteInt(const Variable : String; Data : LongInt);
  244.       {-Write an integer to the INI file}
  245.     procedure WriteBoolean(const Variable : String; Data : Boolean);
  246.       {-Write a boolean to the INI file}
  247.     procedure WriteEnum(const Variable, Vals : String; var Data);
  248.       {-Write an enumerated variable to the INI file}
  249.  
  250.     {reading}
  251.     procedure ReadString(const Variable, DefaultVal : String; var Dest : String);
  252.       {-Read a string from the INI file}
  253.     procedure ReadUCString(const Variable, DefaultVal : String; var Dest : String);
  254.       {-Read an uppercase string from the INI file}
  255.     procedure ReadByte(const Variable : String; DefaultVal : Byte; var Dest : Byte);
  256.       {-Read a byte from the INI file}
  257.     procedure ReadInteger(const Variable : String; DefaultVal : Integer; var Dest : Integer);
  258.       {-Read an integer from the INI file}
  259.     procedure ReadWord(const Variable : String; DefaultVal : Word; var Dest : Word);
  260.       {-Read a word from the INI file}
  261.     procedure ReadLong(const Variable : String; DefaultVal : LongInt; var Dest : LongInt);
  262.       {-Read a longint from the INI file}
  263.     procedure ReadBoolean(const Variable : String; DefaultVal : Boolean; var Dest : Boolean);
  264.       {-Read a boolean from the INI file}
  265.     procedure ReadEnum(const Variable, Vals : String ; var DefaultVal; var Dest);
  266.       {-Read an enumerated variable from the INI file}
  267.   end;
  268.  
  269. var
  270.   {Configuration}
  271.   Config : TIniFile;
  272.  
  273. procedure ReadConfiguration;
  274.   {-Read program options from TCOM.INI}
  275. procedure WriteTerminalOptions;
  276.   {-Write terminal font options to TCOM.INI}
  277. procedure WritePortOptions;
  278.   {-Write communications port options to TCOM.INI}
  279. procedure WriteFlowOptions;
  280.   {-Write flow control options to TCOM.INI}
  281. procedure WriteDeviceOptions;
  282.   {-Write device layer options to TCOM.INI}
  283. procedure WriteDataFileOptions;
  284.   {-Write upload/download directory database options to TCOM.INI}
  285. procedure WriteDialerOptions;
  286.   {-Write dialer options to TCOM.INI}
  287. procedure WriteProtocolOptions;
  288.   {-Write general protocol options to TCOM.INI}
  289. procedure WriteZmodemOptions;
  290.   {-Write Zmodem specific options to TCOM.INI}
  291. procedure WriteBplusOptions;
  292.   {-Write CIS B+ specific options to TCOM.INI}
  293. procedure WriteKermitOptions;
  294.   {-Write Kermit specific options to TCOM.INI}
  295. procedure WriteAsciiOptions;
  296.   {-Write ASCII protocol options to TCOM.INI}
  297.  
  298. function ValidBaud(Baud : LongInt) : Boolean;
  299.   {-Return TRUE if Baud is a valid baud rate}
  300.  
  301. implementation
  302.  
  303.   constructor TIniFile.Create;
  304.   begin
  305.     FileName := '';
  306.     Section  := '';
  307.   end;
  308.  
  309.   destructor TIniFile.Destroy;
  310.   begin
  311.   end;
  312.  
  313.   function TIniFile.ReadSection : String;
  314.   begin
  315.     Result := StrPas(FSection);
  316.   end;
  317.  
  318.   procedure TIniFile.SetSection(const Sect : String);
  319.   begin
  320.     StrPCopy(FSection, Sect);
  321.   end;
  322.  
  323.   function TIniFile.ReadFileName : TFileName;
  324.   begin
  325.     Result := StrPas(FFileName);
  326.   end;
  327.  
  328.   procedure TIniFile.SetFileName(const FName : TFileName);
  329.   begin
  330.     StrPCopy(FFileName, FName);
  331.   end;
  332.  
  333.   procedure TIniFile.WriteString(const Variable, Data : String);
  334.     {-Write a string to the INI file}
  335.   begin
  336.     if (Section = '') then
  337.       raise ENoIniSection.Create(ReadFileName);
  338.  
  339.     WritePrivateProfileString(FSection, StrPCopy(TempVar, Variable),
  340.                               StrPCopy(TempData, Data), FFileName);
  341.   end;
  342.  
  343.   procedure TIniFile.WriteUCString(const Variable, Data : String);
  344.     {-Write an uppercase string to the INI file}
  345.   begin
  346.     WriteString(Variable, UpperCase(Data));
  347.   end;
  348.  
  349.   procedure TIniFile.WriteInt(const Variable : String; Data : LongInt);
  350.     {-Write an integer to the INI file}
  351.   begin
  352.     if (Section = '') then
  353.       raise ENoIniSection.Create(ReadFileName);
  354.  
  355.     WriteString(Variable, IntToStr(Data));
  356.   end;
  357.  
  358.   procedure TIniFile.WriteBoolean(const Variable : String; Data : Boolean);
  359.     {-Write a boolean to the INI file}
  360.   begin
  361.     if (Section = '') then
  362.       raise ENoIniSection.Create(ReadFileName);
  363.  
  364.     WriteString(Variable, IniBoolStr[Data]);
  365.   end;
  366.  
  367.   procedure TIniFile.WriteEnum(const Variable, Vals : String; var Data);
  368.     {-Write an enumerated variable to the INI file}
  369.   var
  370.     I    : Integer;
  371.     B    : Byte absolute Data;
  372.     P    : Integer;
  373.     Temp : String;
  374.  
  375.   begin
  376.     if (Section = '') then
  377.       raise ENoIniSection.Create(ReadFileName);
  378.  
  379.     {find the string associated with this vale}
  380.     if (B > WordCount(Vals, [EnumDelim])) then
  381.       Temp := ''
  382.     else
  383.       Temp := ExtractWord(B + 1, Vals, [EnumDelim]);
  384.  
  385.     {write it out}
  386.     WriteString(Variable, Temp);
  387.   end;
  388.  
  389.   procedure TIniFile.ReadString(const Variable, DefaultVal : String; var Dest : String);
  390.     {-Read a string from the INI file}
  391.   begin
  392.     if (Section = '') then
  393.       raise ENoIniSection.Create(ReadFileName);
  394.  
  395.     GetPrivateProfileString(FSection, StrPCopy(TempVar, Variable),
  396.                             StrPCopy(TempDefault, DefaultVal),
  397.                             TempData, 255, FFileName);
  398.     Dest := StrPas(TempData);
  399.   end;
  400.  
  401.   procedure TIniFile.ReadUCString(const Variable, DefaultVal : String; var Dest : String);
  402.     {-Read an uppercase string from the INI file}
  403.   begin
  404.     if (Section = '') then
  405.       raise ENoIniSection.Create(ReadFileName);
  406.     ReadString(Variable, DefaultVal, Dest);
  407.     Dest := UpperCase(Dest);
  408.   end;
  409.  
  410.   procedure TIniFile.ReadByte(const Variable : String; DefaultVal : Byte; var Dest : Byte);
  411.     {-Read a byte from the INI file}
  412.   const
  413.     ByteTempLen = 3;
  414.  
  415.   var
  416.     Error    : Integer;
  417.     TempByte : String[ByteTempLen];
  418.  
  419.   begin
  420.     ReadString(Variable, IntToStr(DefaultVal), TempByte);
  421.     if (Length(TempByte) > ByteTempLen) and (TempByte <> '') then
  422.       Dest := DefaultVal
  423.     else begin
  424.       Val(TempByte, Dest, Error);
  425.       if (Error <> 0) then
  426.         Dest := DefaultVal;
  427.     end;
  428.   end;
  429.  
  430.   procedure TIniFile.ReadInteger(const Variable : String; DefaultVal : Integer; var Dest : Integer);
  431.     {-Read an integer from the INI file}
  432.   const
  433.     IntegerTempLen = 6;
  434.  
  435.   var
  436.     Error       : Integer;
  437.     TempInteger : String[IntegerTempLen];
  438.  
  439.   begin
  440.     ReadString(Variable, IntToStr(DefaultVal), TempInteger);
  441.     if (Length(TempInteger) > IntegerTempLen) and (TempInteger <> '') then
  442.       Dest := DefaultVal
  443.     else begin
  444.       Val(TempInteger, Dest, Error);
  445.       if (Error <> 0) then
  446.         Dest := DefaultVal;
  447.     end;
  448.   end;
  449.  
  450.   procedure TIniFile.ReadWord(const Variable : String; DefaultVal : Word; var Dest : Word);
  451.     {-Read a word from the INI file}
  452.   const
  453.     WordTempLen = 5;
  454.  
  455.   var
  456.     Error    : Integer;
  457.     TempWord : String[WordTempLen];
  458.  
  459.   begin
  460.     ReadString(Variable, IntToStr(DefaultVal), TempWord);
  461.     if (Length(TempWord) > WordTempLen) and (TempWord <> '') then
  462.       Dest := DefaultVal
  463.     else begin
  464.       Val(TempWord, Dest, Error);
  465.       if (Error <> 0) then
  466.         Dest := DefaultVal;
  467.     end;
  468.   end;
  469.  
  470.   procedure TIniFile.ReadLong(const Variable : String; DefaultVal : LongInt; var Dest : LongInt);
  471.     {-Read a longint from the INI file}
  472.   const
  473.     LongIntTempLen = 12;
  474.  
  475.   var
  476.     Error       : Integer;
  477.     TempLongInt : String[LongIntTempLen];
  478.  
  479.   begin
  480.     ReadString(Variable, IntToStr(DefaultVal), TempLongInt);
  481.     if (Length(TempLongInt) > LongIntTempLen) and (TempLongInt <> '') then
  482.       Dest := DefaultVal
  483.     else begin
  484.       Val(TempLongInt, Dest, Error);
  485.       if (Error <> 0) then
  486.         Dest := DefaultVal;
  487.     end;
  488.   end;
  489.  
  490.   procedure TIniFile.ReadBoolean(const Variable : String; DefaultVal : Boolean; var Dest : Boolean);
  491.     {-Read a boolean from the INI file}
  492.   const
  493.     BoolTempLen = 10;
  494.  
  495.   var
  496.     TempBoolean : String[BoolTempLen];
  497.  
  498.   begin
  499.     ReadUCString(Variable, '', TempBoolean);
  500.     if (TempBoolean = '') then
  501.       Dest := DefaultVal
  502.     else if (TempBoolean = IniBoolStr[FALSE]) then
  503.       Dest := False
  504.     else if (TempBoolean = IniBoolStr[TRUE]) then
  505.       Dest := True
  506.     else if (TempBoolean = 'TRUE') then
  507.       Dest := True
  508.     else if (TempBoolean = 'FALSE') then
  509.       Dest := False
  510.     else if (TempBoolean = 'YES') then
  511.       Dest := True
  512.     else if (TempBoolean = 'NO') then
  513.       Dest := False
  514.     else
  515.       Dest := DefaultVal;
  516.   end;
  517.  
  518.   procedure TIniFile.ReadEnum(const Variable, Vals : String ; var DefaultVal; var Dest);
  519.     {-Read an enumerated variable from the INI file}
  520.   var
  521.     I    : Integer;
  522.     Cnt  : Word;
  523.     B    : Byte absolute Dest;
  524.     Temp : String;
  525.  
  526.   begin
  527.     ReadUCString(Variable, '', Temp);
  528.  
  529.     Cnt := WordCount(Vals, [EnumDelim]);
  530.     for I := 1 to Cnt do
  531.       if (Temp = ExtractWord(I, Vals, [EnumDelim])) then begin
  532.         B := Pred(I);
  533.         Exit;
  534.       end;
  535.  
  536.     B := Byte(DefaultVal);
  537.   end;
  538.  
  539.   function ValidBaud(Baud : LongInt) : Boolean;
  540.     {-Return TRUE if Baud is a valid baud rate}
  541.   begin
  542.     case (Baud div 10) of
  543.       30  ,
  544.       60  ,
  545.       120 ,
  546.       240 ,
  547.       480 ,
  548.       960 ,
  549.       1920,
  550.       3840,
  551.       5760,
  552.       11520: ValidBaud := True;
  553.       else
  554.         ValidBaud := False;
  555.     end;
  556.   end;
  557.  
  558. {TCOM Configuration}
  559.  
  560.   procedure ReadConfiguration;
  561.     {-Read program options from TCOM.INI}
  562.  
  563.     function ValidateComStr : Boolean;
  564.       {-Validate the com port string from the .INI file}
  565.     begin
  566.       ValidateComStr := (Length(Com) = 4) and
  567.                         (Copy(Com, 1, 3) = 'COM') and
  568.                         (Com[4] in ['1'..'8']);
  569.     end;
  570.  
  571.     function HdwFlowFromStr(const Str : String) : THWFlowOptionSet;
  572.       {-Return a hardware flow control mask based on a string}
  573.     begin
  574.       if (Str = 'CTS') or (Str = 'CTS/RTS') or (Str = 'RTS') or (Str = 'RTS/CTS') then
  575.         HdwFlowFromStr := [hwfUseRTS, hwfRequireCTS]
  576.       else if (Str = 'DTR') or (Str = 'DTR/DSR') or (Str = 'DSR') or (Str = 'DSR/DTR') then
  577.         HdwFlowFromStr := [hwfUseDTR, hwfRequireDSR]
  578.       else
  579.         HdwFlowFromStr := [];
  580.     end;
  581.  
  582.     procedure ReadTerminalOptions;
  583.     var
  584.       I         : Word;
  585.       Cnt       : Word;
  586.       TempLong  : LongInt;
  587.       TempInt   : Integer;
  588.       TempStyle : TFontStyles;
  589.       TempPitch : TFontPitch;
  590.       TempSt    : String;
  591.  
  592.     (*const                                           {!!.01}
  593.       DefEmulation : TEmulatorType = tdEmulation;   {!!.01} *)
  594.  
  595.  
  596.       function StrToStyle(const St : String) : TFontStyle;
  597.       begin
  598.         if (St = 'BOLD') then
  599.           Result := fsBold
  600.         else if (St = 'ITALIC') then
  601.           Result := fsItalic
  602.         else if (St = 'UNDERLINE') then
  603.           Result := fsUnderline
  604.         else
  605.           Result := fsStrikeout;
  606.       end;
  607.  
  608.     begin
  609.       Config.Section := tsTerminal;
  610.  
  611.       Config.ReadLong(tkFontColor, tdFontColor, TempLong);
  612.       FontData.Color := TempLong;
  613.       Config.ReadInteger(tkFontHeight, tdFontHeight, TempInt);
  614.       FontData.Height := TempInt;
  615.       Config.ReadString(tkFontName, tdFontName, TempSt);
  616.       FontData.Name := TempSt;
  617.       FontData.Pitch := fpFixed;
  618.  
  619.       Config.ReadString(tkFontStyle, '', TempSt);
  620.       TempStyle := [];
  621.       Cnt := WordCount(TempSt, [',', ' ']);
  622.       for I := 1 to Cnt do
  623.         TempStyle := TempStyle + [StrToStyle(ExtractWord(I, TempSt, [',', ' ']))];
  624.       FontData.Style := TempStyle;
  625.  
  626.       (*Config.ReadEnum(tkEmulation, eEmulations, DefEmulation, Emulation);{!!.01}*)
  627.     end;
  628.  
  629.     procedure ReadPortOptions;
  630.       {-Read communications port options from TCOM.INI}
  631.     const
  632.       DefParity : TParity = tdParity;
  633.  
  634.     begin
  635.       Config.Section := tsPort;
  636.  
  637.       Config.ReadUCString(tkComPort, tdComPort, Com);
  638.       if not ValidateComStr then
  639.         Com := tdComPort;
  640.  
  641.       Config.ReadLong(tkBaudRate, tdBaudRate, Baud);
  642.       if not ValidBaud(Baud) then
  643.         Baud := tdBaudRate;
  644.  
  645.       Config.ReadEnum(tkParity, eParities, DefParity, Parity);
  646.  
  647.       Config.ReadByte(tkDataBits, tdDataBits, DataBits);
  648.       if (DataBits < 5) or (DataBits > 8) then
  649.         DataBits := 8;
  650.  
  651.       Config.ReadByte(tkStopBits, tdStopBits, StopBits);
  652.       if (StopBits < 1) or (StopBits > 2) then
  653.         StopBits := 1;
  654.     end;
  655.  
  656.     procedure ReadFlowOptions;
  657.       {-Read port flow control options from TCOM.INI}
  658.     var
  659.       B    : Boolean;
  660.       Temp : String[80];
  661.  
  662.     begin
  663.       Config.Section := tsFlow;
  664.  
  665.       Config.ReadUCString(tkHWFlow, tdHWFlow, Temp);
  666.       HdwFlow := HdwFlowFromStr(Temp);
  667.  
  668.       SfwFlow := swfNone;
  669.       Config.ReadBoolean(tkSWFlowRecCtl, tdSWFlowRecCtl, B);
  670.       if B then
  671.         SfwFlow := swfReceive;
  672.  
  673.       Config.ReadBoolean(tkSWFlowXmitCtl, tdSWFlowXmitCtl, B);
  674.       if B then
  675.         if (SfwFlow <> swfNone) then
  676.           SfwFlow := swfBoth
  677.         else
  678.           SfwFlow := swfTransmit;
  679.  
  680.       Config.ReadByte(tkXonChar, tdXonChar, Byte(XonChar));
  681.       Config.ReadByte(tkXoffChar, tdXoffChar, Byte(XoffChar));
  682.     end;
  683.  
  684.     procedure ReadDeviceOptions;
  685.       {-Read device layer options from TCOM.INI}
  686.     const
  687.       DefDevice : TDeviceLayer = tdDevice;
  688.  
  689.     begin
  690.       Config.Section := tsDev;
  691.       Config.ReadWord(tkBufSize, tdBufSize, InBuff);
  692.       if (InBuff = 0) then
  693.         InBuff := 16384;
  694.       OutBuff      := 16384;
  695.       BufferFull   := LongInt(InBuff) * 80 div 100;
  696.       BufferResume := LongInt(InBuff) * 20 div 100;
  697.  
  698.       Config.ReadEnum(tkDevice, eDevices, DefDevice, Device);
  699.     end;
  700.  
  701.     procedure ReadDataFileOptions;
  702.       {-Read modem, path and directory options from TCOM.INI}
  703.     var
  704.       Code   : Integer;
  705.       Temp   : String[80];
  706.  
  707.     begin
  708.       Config.Section := tsDirs;
  709.  
  710.       Temp := JustPathName(FullPathName(ParamStr(0)));
  711.       Config.ReadUCString(tkUploadDir, Temp, UploadDir);
  712.       Config.ReadUCString(tkDownloadDir, Temp, DownloadDir);
  713.  
  714.       Temp := AddBackslash(Temp);
  715.  
  716.       {$IFDEF Tracing}
  717.       TraceFile   := Temp + 'TCOM.TRC';
  718.       {$ENDIF}
  719.       {$IFDEF DispatchLogging}
  720.       DispLogFile := Temp + 'TCOM.LOG';
  721.       {$ENDIF}
  722.       DBFile      := Temp + 'AWMODEM.INI';
  723.       LogFile     := Temp + 'TCOM.HIS';
  724.       PhoneFile   := Temp + 'TCOM.PB';
  725.       CaptureFile := Temp + 'CAPTURE.CAP';
  726.     end;
  727.  
  728.     procedure ReadDialerOptions;
  729.       {-Read modem dialer options from TCOM.INI}
  730.     var
  731.       AbortOnVoice      : Boolean;
  732.       AbortOnBusy       : Boolean;
  733.       AbortOnNoCarrier  : Boolean;
  734.       AbortOnNoDialTone : Boolean;
  735.       AbortOnError      : Boolean;
  736.  
  737.     begin
  738.       Config.Section := tsDialer;
  739.  
  740.       Config.ReadInteger(tkRetries, tdRetries, MaxDialTries);
  741.       Config.ReadInteger(tkRetryWait, tdRetryWait, RetryTime);
  742.       Config.ReadBoolean(tkAbortOnVoice, tdAbortOnVoice, AbortOnVoice);
  743.       Config.ReadBoolean(tkAbortOnBusy, tdAbortOnBusy, AbortOnBusy);
  744.       Config.ReadBoolean(tkAbortOnNC, tdAbortOnNC, AbortOnNoCarrier);
  745.       Config.ReadBoolean(tkAbortOnND, tdAbortOnND, AbortOnNoDialTone);
  746.       Config.ReadBoolean(tkAbortOnError, tdAbortOnError, AbortOnError);
  747.  
  748.       if AbortOnVoice then
  749.         DialerOpts := DialerOpts + [mdAbortOnVoice];
  750.       if AbortOnBusy then
  751.         DialerOpts := DialerOpts + [mdAbortOnBusy];
  752.       if AbortOnNoCarrier then
  753.         DialerOpts := DialerOpts + [mdAbortOnNoCarrier];
  754.       if AbortOnNoDialTone then
  755.         DialerOpts := DialerOpts + [mdAbortOnNoDialTone];
  756.       if AbortOnError then
  757.         DialerOpts := DialerOpts + [mdAbortOnError];
  758.     end;
  759.  
  760.     procedure ReadProtocolOptions;
  761.       {-Read general file transfer protocol options from TCOM.INI}
  762.     const
  763.       DefOverwriteMode : TWriteFailAction = tdOverwriteMode;
  764.  
  765.     begin
  766.       Config.Section := tsProtocols;
  767.  
  768.       Config.ReadEnum(tkOverwriteMode, eOverwriteModes, DefOverwriteMode, WriteOpt);
  769.       Config.ReadBoolean(tkSavePartials, tdSavePartials, SavePartials);
  770.       Config.ReadBoolean(tkRTSWrite, tdRTSWrite, RTSWrite);
  771.     end;
  772.  
  773.     procedure ReadZmodemOptions;
  774.       {-Read Zmodem protocol options from TCOM.INI}
  775.     begin
  776.       Config.Section := tsZmodem;
  777.       Config.ReadBoolean(tkZmodemAutoSt, tdZmodemAutoSt, ZmodemAutoSt);
  778.     end;
  779.  
  780.     procedure ReadBplusOptions;
  781.       {-Read B+ protocol options from TCOM.INI}
  782.     begin
  783.       Config.Section := tsBplus;
  784.       Config.ReadBoolean(tkBplusEnabled, tdBplusEnabled, BplusEnabled);
  785.     end;
  786.  
  787.     procedure ReadKermitOptions;
  788.       {-Read Kermit protocol options from TCOM.INI}
  789.     const
  790.       DefKermitErrChk : Byte = Ord(tdKermitErrChk);
  791.  
  792.     begin
  793.       Config.Section := tsKermit;
  794.       Config.ReadEnum(tkKermitErrChk, eKermitCheck, DefKermitErrChk, ErrCheck);
  795.       Inc(Byte(ErrCheck), Ord('1'));
  796.  
  797.       Config.ReadByte(tkHiBitPrefix, tdHiBitPrefix, Byte(HiBitPrefix));
  798.       Config.ReadByte(tkRepeatPrefix, tdRepeatPrefix, Byte(RepeatPrefix));
  799.       Config.ReadByte(tkControlPrefix, tdControlPrefix, Byte(CtlPrefix));
  800.       Config.ReadByte(tkPaddingCount, tdPaddingCount, PadCount);
  801.       Config.ReadByte(tkPaddingChar, tdPaddingChar, Byte(PadChar));
  802.       Config.ReadByte(tkMaxPackLength, tdMaxPackLength, MaxPacketLen);
  803.       Config.ReadByte(tkTerminator, tdTerminator, Byte(Terminator));
  804.     end;
  805.  
  806.     procedure ReadAsciiOptions;
  807.       {-Read ASCII protocol options from TCOM.INI}
  808.     const
  809.       DefUplCRXlat : TAsciiEOLTranslation = tdUploadCR;
  810.       DefUplLFXlat : TAsciiEOLTranslation = tdUploadLF;
  811.       DefDwnCRXlat : TAsciiEOLTranslation = tdDownloadCR;
  812.       DefDwnLFXlat : TAsciiEOLTranslation = tdDownloadLF;
  813.  
  814.     begin
  815.       Config.Section := tsAscii;
  816.  
  817.       Config.ReadEnum(tkUploadCR, eUplCRXlat, DefUplCRXlat, UploadCR);
  818.       Config.ReadEnum(tkUploadLF, eUplLFXlat, DefUplLFXlat, UploadLF);
  819.  
  820.       Config.ReadBoolean(tkStopCtrlZ, tdStopCtrlZ, StopCtrlZ);
  821.  
  822.       Config.ReadByte(tkEolCharacter, tdEolCharacter, Byte(EolChar));
  823.       Config.ReadWord(tkDelayChar, tdDelayChar, DelayChar);
  824.       Config.ReadWord(tkDelayLine, tdDelayLine, DelayLine);
  825.  
  826.       Config.ReadEnum(tkDownloadCR, eDwnCRXlat, DefDwnCRXlat, DownloadCR);
  827.       Config.ReadEnum(tkDownloadLF, eDwnLFXlat, DefDwnLFXlat, DownloadLF);
  828.  
  829.       Config.ReadWord(tkTimeout, tdTimeout, AscTimeout);
  830.     end;
  831.  
  832.   begin
  833.     if not Assigned(Config) then begin
  834.       Config := TIniFile.Create;
  835.       Config.FileName := IniName;
  836.     end;
  837.  
  838.     ReadTerminalOptions;
  839.     ReadPortOptions;
  840.     ReadFlowOptions;
  841.     ReadDeviceOptions;
  842.     ReadDataFileOptions;
  843.     ReadDialerOptions;
  844.     ReadProtocolOptions;
  845.     ReadZmodemOptions;
  846.     ReadBplusOptions;
  847.     ReadKermitOptions;
  848.     ReadAsciiOptions;
  849.   end;
  850.  
  851. const
  852.   OffOn : array[False..True] of array[0..3] of Char =
  853.     ('OFF', 'ON');
  854.  
  855.   function HWFlowStr(Flow : THWFlowOptionSet) : String;
  856.     {-Return a string based on flow control options}
  857.   begin
  858.     if hwfUseRTS in Flow then
  859.       Result := 'RTS/CTS'
  860.     else if hwfUseDTR in Flow then
  861.       Result := 'DTR/DSR'
  862.     else
  863.       Result := 'NONE';
  864.   end;
  865.  
  866.   procedure WriteTerminalOptions;
  867.     {-Write terminal font options to TCOM.INI}
  868.   const
  869.     StyleNames : array[TFontStyle] of String[10] =
  870.       ('BOLD', 'ITALIC', 'UNDERLINE', 'STRIKEOUT');
  871.  
  872.   var
  873.     Style    : TFontStyle;
  874.     OutStyle : String;
  875.  
  876.   begin
  877.     Config.Section := tsTerminal;
  878.  
  879.     Config.WriteInt(tkFontColor, FontData.Color);
  880.     Config.WriteInt(tkFontHeight, FontData.Height);
  881.     Config.WriteString(tkFontName, FontData.Name);
  882.  
  883.     {construct style string}
  884.     OutStyle := '';
  885.     for Style := fsBold to fsStrikeout do
  886.       if Style in FontData.Style then
  887.         OutStyle := OutStyle + StyleNames[Style] + ',';
  888.     {remove trailing comma if necessary}
  889.     if (Length(OutStyle) <> 0) then
  890.       Dec(OutStyle[0]);
  891.  
  892.     Config.WriteString(tkFontStyle, OutStyle);
  893.  
  894.     (*{!!.01 - Added}
  895.     Config.WriteEnum(tkEmulation, eEmulations, Emulation);*)
  896.   end;
  897.  
  898.   procedure WritePortOptions;
  899.     {-Write communications port options to TCOM.INI}
  900.   begin
  901.     Config.Section := tsPort;
  902.  
  903.     Config.WriteUCString(tkComPort, Com);
  904.     Config.WriteInt(tkBaudRate, Baud);
  905.     Config.WriteEnum(tkParity, eParities, Parity);
  906.     Config.WriteInt(tkDataBits, DataBits);
  907.     Config.WriteInt(tkStopBits, StopBits);
  908.   end;
  909.  
  910.   procedure WriteFlowOptions;
  911.     {-Write flow control options to TCOM.INI}
  912.   begin
  913.     Config.Section := tsFlow;
  914.  
  915.     Config.WriteUCString(tkHWFlow, HWFlowStr(HdwFlow));
  916.     Config.WriteBoolean(tkSWFlowRecCtl, (SfwFlow = swfReceive) or (SfwFlow = swfBoth));
  917.     Config.WriteBoolean(tkSWFlowXmitCtl, (SfwFlow = swfTransmit) or (SfwFlow = swfBoth));
  918.     Config.WriteInt(tkXonChar, Ord(XonChar));
  919.     Config.WriteInt(tkXoffChar, Ord(XoffChar));
  920.   end;
  921.  
  922.   procedure WriteDeviceOptions;
  923.     {-Write device layer options to TCOM.INI}
  924.   begin
  925.     Config.Section := tsDev;
  926.  
  927.     Config.WriteInt(tkBufSize, InBuff);
  928.     Config.WriteEnum(tkDevice, eDevices, Device);
  929.   end;
  930.  
  931.   procedure WriteDataFileOptions;
  932.     {-Write upload/download directory database options to TCOM.INI}
  933.   var
  934.     Code : Integer;
  935.  
  936.   begin
  937.     Config.Section := tsDirs;
  938.  
  939.     Config.WriteUCString(tkUploadDir, UploadDir);
  940.     Config.WriteUCString(tkDownloadDir, DownloadDir);
  941.   end;
  942.  
  943.   procedure WriteDialerOptions;
  944.     {-Write dialer options to TCOM.INI}
  945.   begin
  946.     Config.Section := tsDialer;
  947.  
  948.     Config.WriteInt(tkRetries, MaxDialTries);
  949.     Config.WriteInt(tkRetryWait, RetryTime);
  950.     Config.WriteBoolean(tkAbortOnVoice, mdAbortOnVoice in DialerOpts);
  951.     Config.WriteBoolean(tkAbortOnBusy, mdAbortOnBusy in DialerOpts);
  952.     Config.WriteBoolean(tkAbortOnNC, mdAbortOnNoCarrier in DialerOpts);
  953.     Config.WriteBoolean(tkAbortOnND, mdAbortOnNoDialTone in DialerOpts);
  954.     Config.WriteBoolean(tkAbortOnError, mdAbortOnError in DialerOpts);
  955.   end;
  956.  
  957.   procedure WriteProtocolOptions;
  958.     {-Write general protocol options to TCOM.INI}
  959.   begin
  960.     Config.Section := tsProtocols;
  961.  
  962.     Config.WriteEnum(tkOverwriteMode, eOverwriteModes, WriteOpt);
  963.     Config.WriteBoolean(tkSavePartials, SavePartials);
  964.     Config.WriteBoolean(tkRTSWrite, RTSWrite);
  965.   end;
  966.  
  967.   procedure WriteZmodemOptions;
  968.     {-Write Zmodem specific options to TCOM.INI}
  969.   begin
  970.     Config.Section := tsZmodem;
  971.     Config.WriteBoolean(tkZmodemAutoSt, ZmodemAutoSt);
  972.   end;
  973.  
  974.   procedure WriteBplusOptions;
  975.     {-Write CIS B+ specific options to TCOM.INI}
  976.   begin
  977.     Config.Section := tsBplus;
  978.     Config.WriteBoolean(tkBplusEnabled, BplusEnabled);
  979.   end;
  980.  
  981.   procedure WriteKermitOptions;
  982.     {-Write Kermit specific options to TCOM.INI}
  983.   var
  984.     TempCheck : Byte;
  985.  
  986.   begin
  987.     Config.Section := tsKermit;
  988.  
  989.     TempCheck := Ord(ErrCheck) - Ord('1');
  990.     Config.WriteEnum(tkKermitErrChk, eKermitCheck, TempCheck);
  991.  
  992.     Config.WriteInt(tkHiBitPrefix, Ord(HiBitPrefix));
  993.     Config.WriteInt(tkRepeatPrefix, Ord(RepeatPrefix));
  994.     Config.WriteInt(tkControlPrefix, Ord(CtlPrefix));
  995.     Config.WriteInt(tkPaddingCount, PadCount);
  996.     Config.WriteInt(tkPaddingChar, Ord(PadChar));
  997.     Config.WriteInt(tkMaxPackLength, MaxPacketLen);
  998.     Config.WriteInt(tkTerminator, Ord(Terminator));
  999.   end;
  1000.  
  1001.   procedure WriteAsciiOptions;
  1002.     {-Write ASCII protocol options to TCOM.INI}
  1003.   begin
  1004.     Config.Section := tsAscii;
  1005.  
  1006.     Config.WriteEnum(tkUploadCR, eUplCRXlat, UploadCR);
  1007.     Config.WriteEnum(tkUploadLF, eUplLFXlat, UploadLF);
  1008.     Config.WriteBoolean(tkStopCtrlZ, StopCtrlZ);
  1009.     Config.WriteInt(tkEolCharacter, Ord(EolChar));
  1010.     Config.WriteInt(tkDelayChar, DelayChar);
  1011.     Config.WriteInt(tkDelayLine, DelayLine);
  1012.     Config.WriteEnum(tkDownloadCR, eDwnCRXlat, DownloadCR);
  1013.     Config.WriteEnum(tkDownloadLF, eDwnLFXlat, DownloadLF);
  1014.     Config.WriteInt(tkTimeout, AscTimeout);
  1015.   end;
  1016.  
  1017. initialization
  1018.   Config := nil;
  1019. end.
  1020.